<template>
  <div>
    <i :class="isFullscreen ? 'el-icon-full-screen' : 'el-icon-full-screen'" @click="handleClick" />
    <!-- <svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="handleClick" /> -->
  </div>
</template>

<script>
// "screenfull": "^5.0.2",
import screenfull from 'screenfull';
export default {
  name: 'Screenfull',
  data() {
    return {
      isFullscreen: false
    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    handleClick() {
      // if (!screenfull.enabled) {
      //   this.$message({
      //     message: 'you browser can not work',
      //     type: 'warning'
      //   })
      //   return false
      // }
      screenfull.toggle();
      screenfull.on('change', this.change);
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on('change', this.change);
      }
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off('change', this.change);
      }
    }
  }
};
</script>

<style scoped>
.svg-icon {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;
  width: 20px;
  height: 20px;
}
</style>
